package com.xyy.saas.payment.merchant.core.dto;

import com.xyy.saas.payment.common.exception.PaymentException;
import com.xyy.saas.payment.cores.enums.ResultCodeEnum;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

@Data
@Builder
public class RechargeHandleDto {
    // 支付
    public static final String PAY = "pay";
    // 退款
    public static final String REFUND = "refund";

    /**
     * 充值类型
     * 支付 pay
     * 退款 refund
     */
    private String rechargeType;
    /**
     * 支付平台商户标识
     */
    private String accountId;
    /**
     * 支付/退款渠道
     */
    public String channel;
    /**
     * 支付流水号/退款流水号
     */
    private String orderNo;

    /**
     * 参数校验
     */
    public void checkParam() throws PaymentException {
        if(StringUtils.isBlank(rechargeType)) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "充值类型为空");
        }

        if(StringUtils.isBlank(accountId)) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "商户标识为空");
        }

        if(StringUtils.isBlank(channel)) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "渠道为空");
        }

        if(StringUtils.isBlank(orderNo)) {
            throw new PaymentException(ResultCodeEnum.PARAM_ERROR.getCode(), "单号为空");
        }
    }
}
